// Copyright 2012 Square, Inc.
package org.assertj.ohos.api.widget;

import ohos.agp.components.Component;
import ohos.agp.components.PageFlipper;
import org.assertj.ohos.api.Assertions;
import org.assertj.ohos.api.view.AbstractViewGroupAssert;

import static org.assertj.core.api.Assertions.assertThat;

public abstract class AbstractViewAnimatorAssert<S extends AbstractViewAnimatorAssert<S, A>, A extends PageFlipper>
    extends AbstractViewGroupAssert<S, A> {
  public AbstractViewAnimatorAssert(A actual, Class<S> selfType) {
    super(actual, selfType);
  }

  private Component getDisplayedView() {
    return actual.getComponentAt(actual.getCurrentIndex());
  }

  public S hasDisplayedChild(Component view) {
    isNotNull();
    Component actualView = getDisplayedView();
    assertThat(actualView) //
        .overridingErrorMessage("Expected displayed child <%s> but was <%s>.", view, actualView) //
        .isSameAs(view);
    return myself;
  }

  public S hasDisplayedChildId(int id) {
    isNotNull();
    Assertions.assertThat(getDisplayedView()).hasId(id);
    return myself;
  }

  public S hasDisplayedChild(int index) {
    isNotNull();
    int actualIndex = actual.getCurrentIndex();
    assertThat(actualIndex) //
        .overridingErrorMessage("Expected displayed child index <%s> but was <%s>.", index,
            actualIndex) //
        .isEqualTo(index);
    return myself;
  }
}
